﻿using System;
using System.Linq;
using SampleWebApplication.Data;

namespace SampleWebApplication
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_PreRender(object sender, EventArgs e)
        {
            var manager = new DataManager();

            DepartmentsGrid.DataSource = manager.GetDepartments();
            DepartmentsGrid.DataBind();

            ContactsGrid.DataSource = from c in manager.GetContacts()
                                      select new { c.ID, c.FirstName, c.LastName, c.Department.Name };
            ContactsGrid.DataBind();
        }

        protected void AddDepartments_Click(object sender, EventArgs e)
        {
            var manager = new DataManager();
            manager.AddDepartment("Sales");
            manager.AddDepartment("Information Technology");
            manager.AddDepartment("Management");
            manager.AddDepartment("Accounting");
        }

        protected void AddContacts_Click(object sender, EventArgs e)
        {
            var manager = new DataManager();
            manager.AddContact("Gabe", "Sumner", manager.GetDepartment("Sales"));
            manager.AddContact("Joshua", "Holt", manager.GetDepartment("Information Technology"));
            manager.AddContact("Robert", "Shoemate", manager.GetDepartment("Management"));
            manager.AddContact("Todd", "Anglin", manager.GetDepartment("Accounting"));
        }
    }
}
